package Java.view.game.dian21;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;

import java.awt.*;

public class Poker extends StackPane {

    private dian21FX gameFX;
    private String name;
    private int value;
    private boolean up;
    private ImageView imageView;

    public Poker(dian21FX gameFX, String name, int value, boolean up) {
        this.gameFX = gameFX;
        this.name = name;
        this.value = value % 13 + 1;
        if (this.value > 10) {
            this.value = 10;
        }
        this.up = up;

        imageView = new ImageView();
        setImage();

        this.getChildren().add(imageView);
        this.setPrefSize(110, 150);
        this.setVisible(true);
    }

    private void setImage() {
        if (this.up) {
            imageView.setImage(new Image("file:image/" + name + ".jpg"));
        } else {
            imageView.setImage(new Image("file:image/rear.png"));
        }
    }

    public dian21FX getGameFX() {
        return gameFX;
    }

    public void setGameFX(dian21FX gameFX) {
        this.gameFX = gameFX;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public boolean isUp() {
        return up;
    }

    public void setUp(boolean up) {
        this.up = up;
        setImage();
    }


    public ImageView getImageView() {
        return imageView;
    }

    public void setImageView(ImageView imageView) {
        this.imageView = imageView;
    }


    @Override
    public String toString() {
        return "Poker{" +
                "gameFX=" + gameFX +
                ", name='" + name + '\'' +
                ", value=" + value +
                ", up=" + up +
                '}';
    }
    //获得坐标
    public Point getLocation() {
        return new Point((int) this.getLayoutX(), (int) this.getLayoutY());
    }
    //显示牌的正面
    public void turnFront() {
        this.setUp(true);
        setImage();
    }
}